#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/11/8 09:55
# @Author  : youfeng
import time

from basic_upload import BasicUpload
from hive_upload import HiveUpload
from jtpx_upload import JtpxUpload
from label_upload import LabelUpload
from logger import AppLogger
from mining_upload import MiningUpload
from runtime import RunTime

g_logger = AppLogger('upload_sftp.log').get_logger()

# 运行时单进程控制
g_run_time = RunTime(g_logger)


class UploadSftp(object):
    __BASIC_PATH = '/home/work/changsha_project/basic_data'
    __JTPX_PATH = '/home/work/changsha_project/jtpx_data'
    __LABEL_PATH = '/home/work/changsha_project/label_data'
    __MINING_PATH = '/home/work/changsha_project/mining_data'
    __HIVE_PATH = '/home/work/changsha_project/hive_data'

    def __init__(self, log):
        self.log = log

    def __basic_scan(self):
        basic_upload_obj = BasicUpload(self.__BASIC_PATH, self.log)
        basic_upload_obj.upload()
        basic_upload_obj.close()

    def __jtpx_scan(self):
        jtpx_upload_obj = JtpxUpload(self.__JTPX_PATH, self.log)
        jtpx_upload_obj.upload()
        jtpx_upload_obj.close()

    def __label_scan(self):
        label_upload_obj = LabelUpload(self.__LABEL_PATH, self.log)
        label_upload_obj.upload()
        label_upload_obj.close()

    def __mining_scan(self):
        mining_upload_obj = MiningUpload(self.__MINING_PATH, self.log)
        mining_upload_obj.upload()
        mining_upload_obj.close()

    def __hive_scan(self):
        hive_upload_obj = HiveUpload(self.__HIVE_PATH, self.log)
        hive_upload_obj.upload()
        hive_upload_obj.close()

    # 启动扫描
    def start_scan(self):
        self.__basic_scan()
        self.__jtpx_scan()
        self.__label_scan()
        self.__mining_scan()
        self.__hive_scan()


def main():
    start_time = time.time()
    g_logger.info("开始扫描目录文件...")
    upload_sftp_obj = UploadSftp(g_logger)
    upload_sftp_obj.start_scan()
    g_logger.info("目录扫描完成, 耗时: {} s".format(time.time() - start_time))


if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        g_logger.error("执行异常: ")
        g_logger.exception(e)
